package 力扣日常刷题.木22二月.第02天207;

import 力扣日常刷题.ListNode;

/**
 * @author 帅小伙
 * @date 2022/2/7
 * @description
 */
public class Demo21链表中倒数第k个节点 {


    public ListNode getKthFromEnd(ListNode head,int k) {
        int res = 0;
        ListNode temp = head;
        while(temp != null) {
            res ++;
            temp = temp.next;
        }
        temp = head;
        for (int i = 1; i <= res - k ; i++) temp = temp.next;
        return temp;
    }
}
